package org.example;

import org.example.vo.UploadProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * Hello world!
 *
 */
@AutoConfiguration
@ComponentScan("org.example")
@ConditionalOnProperty(prefix = "vcode",name = "enable")
public class UploadApp implements WebMvcConfigurer {

    @Autowired
    UploadProperties uploadProperties;

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        uploadProperties.getMapper().forEach(ui->{
            registry.addResourceHandler(ui.getWebPath())
                    .addResourceLocations(ui.getDiskPath());
        });

    }
}
